<form class="layui-form seller-form"  action="" >
    <div class="layui-form-item">
        <div class="layui-inline">
            <button type="button" id="exportBtn" class="layui-btn layui-btn-sm layui-btn-disabled"  lay-submit lay-filter="exportStatisticsByDorm" disabled><i class="iconfont icon-clouddownload" style="font-size: 20px !important;"></i>导出</button>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="statisticsByDormTable" lay-filter="statisticsByDormTable"></table>
</div>

<div id="exportStatisticsByDorm" style="display: none;">
    <form class="layui-form export-form"  action="" >
        <div class="layui-form-item">
            <div class="layui-margin-10">
                <blockquote class="layui-elem-quote layui-text">
                    请先选中或筛选要导出的数据
                </blockquote>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <input type="text" name="taskname" lay-verify="title" style="width:200px;" placeholder="请输入任务名称" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>

<script>
    layui.use(['table','form','layer'],function(){
        var layer = layui.layer, table = layui.table,form = layui.form;
        //执行渲染
        var statisticsTable = table.render({
            elem: '#statisticsByDormTable', //指定原始表格元素选择器（推荐id选择器）
            height: 'full-115',
            cellMinWidth: '80',
            id:'statisticsByDormTable',
            url: "{:url('Apartment/statisticsByDorm')}",
            cols: [[ //标题栏
                {type:'numbers'},
                {field: 'dormName', title: '宿舍楼', width:120, align:'center'}, 
                {field: 'ffnum', title: '发放人数', width:120, align:'center'}, 
            ]],
            done: function(res, curr, count){
                // 判断加载结果数量是否大于0
                if(count>0){
                    $("#exportBtn").removeClass("layui-btn-disabled");
                    $('#exportBtn').removeAttr("disabled");
                } else {
                    $('#exportBtn').addClass("layui-btn-disabled");
                    $('#exportBtn').attr("disabled", true);
                }
            }
        });
  
        //宿舍发放进度导出
        layui.form.on('submit(exportStatisticsByDorm)', function(data){
            layer.open({
                type: 1,
                title:'宿舍发放进度导出',
                area: ['400px', '248px'], //宽高
                btn:['确定','取消'],
                content: $("#exportStatisticsByDorm").html(),
                success: function () {
                    $(':focus').blur();
                    this.enterEsc = function(event){
                        if(event.keyCode === 13){
                            if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                            $(".layui-layer-btn0").addClass("layui-btn-disabled");

                            var data = $(".export-form:last").serializeArray();
                            if($.trim(data[0]['value']) == '') {
                                layer.msg('请填写任务名称！', { time: 1300 });
                                $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                return false;
                            }
                            
                            data.push({'name':'model','value':'ApartmentByDorm'});

                            JsPost("{:url('Ietask/export')}",data,function(res){
                                    layer.msg(res.msg, {time:1500}, function(){
                                        if(res.status){ 
                                            layer.closeAll();
                                            //执行跳转
                                            var topLayui = parent === self ? layui : top.layui;
                                            topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                        } else { 
                                            $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                        }
                                    });
                                }
                            );
                        }
                            return false; //阻止系统默认回车事件
                        }
                    };
                    $(document).on('keydown', this.enterEsc);	//监听键盘事件，关闭层
                },
                yes:function () {
                    if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                        $(".layui-layer-btn0").addClass("layui-btn-disabled");

                        var data = $(".export-form:last").serializeArray();
                        if($.trim(data[0]['value']) == '') {
                            layer.msg('请填写任务名称！', { time: 1300 });
                            $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                            return false;
                        }

                        data.push({'name':'model','value':'ApartmentByDorm'});

                        JsPost("{:url('Ietask/export')}",data,function(res){
                                layer.msg(res.msg, {time:1500}, function(){
                                    if(res.status){
                                        layer.closeAll();
                                        //执行跳转
                                        var topLayui = parent === self ? layui : top.layui;
                                        topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                    } else { 
                                        $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                    }
                                });
                            }
                        );
                    }
                },btn2:function () {
                    layer.closeAll();
                }, end: function(){
                    $(document).off('keydown', this.enterEsc);	        //解除键盘关闭事件
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>